#pragma once
#include "RBTree.h"

namespace ljl
{

	template<class K, class V>
	struct mapKofT
	{
		K operator()(pair<K, V> p)
		{
			return p.first;
		}
	};

	template<class K, class V>
	class mymap
	{
	public:
		typedef typename RBTree<K, pair<const K, V>, mapKofT<K, V>>::iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, mapKofT<K, V>>::const_iterator const_iterator;


		pair<iterator, bool> insert(const pair<K, V> kv)
		{
			return _t.insert(kv);
		}

		V& operator[](K k)
		{
			pair<iterator, bool> ret = _t.insert(make_pair(k, V()));
			return ret.first->second;

		}

		iterator begin()
		{
			return _t.begin();
		}
		iterator end()
		{
			return _t.end();
		}

		const_iterator begin() const
		{
			return _t.begin();
		}
		const_iterator end() const 
		{
			return _t.end();
		}
	private:
		RBTree<K, pair<const K, V>, mapKofT<K, V>> _t;
	};
}